(function() {
    'use strict';

    angular
        .module('OnlineCashierdesk')
        .run(runBlock);

    /** @ngInject */
    function runBlock($rootScope, $cookies, $state, $stateParams, CONFIG,$modalStack, $timeout) {
        $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams, $urlRouter) {
            // when state change starts, check sessionstorage whether contains current_user or not.
            $modalStack.dismissAll();
            $rootScope.previousState = fromState.name; // 上一个state
            $rootScope.nextState = toState.name; // 下一个state
            $rootScope.errorMsg = '';
            $rootScope.showCompareBox = false;
            $rootScope.moment = window.moment;
            // 
            // if (toState.name === 'cashierdesk') {
            //     $state.go('cashierdesk');
            // }
        });

        $rootScope.$on('$stateChangeSuccess', function(event, fromState, toState) {

        });

        $rootScope.CONFIG = CONFIG;

        if (CONFIG.OFFLINE) {
        }

        // 次函数监控页面刷新事件，需要注意浏览器兼容性(风险点)。
        window.addEventListener('beforeunload', function(event) {
            return null;
        });
    }
})();
